home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
tpu-extras.el
< prev
next >
Wrap
Text File
|
1996-01-20
|
18KB
|
478 lines
;;; tpu-extras.el --- Scroll margins and free cursor mode for TPU-edt
;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
;; Author: Rob Riepel <riepel@networking.stanford.edu>
;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
;; Keywords: emulations
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Use the functions defined here to customize TPU-edt to your tastes by
;; setting scroll margins and/or turning on free cursor mode. Here's an
;; example for your .emacs file.
;; (tpu-set-cursor-free) ; Set cursor free.
;; (tpu-set-scroll-margins "10%" "15%") ; Set scroll margins.
;; Scroll margins and cursor binding can be changed from within emacs using
;; the following commands:
;; tpu-set-scroll-margins or set scroll margins
;; tpu-set-cursor-bound or set cursor bound
;; tpu-set-cursor-free or set cursor free
;; Additionally, Gold-F toggles between bound and free cursor modes.
;; Note that switching out of free cursor mode or exiting TPU-edt while in
;; free cursor mode strips trailing whitespace from every line in the file.
;;; Details:
;; The functions contained in this file implement scroll margins and free
;; cursor mode. The following keys and commands are affected.
;; key/command function scroll cursor
;; Up-Arrow previous line x x
;; Down-Arrow next line x x
;; Right-Arrow next character x
;; Left-Arrow previous character x
;; KP0 next or previous line x
;; KP7 next or previous page x
;; KP8 next or previous screen x
;; KP2 next or previous end-of-line x x
;; Control-e current end-of-line x
;; Control-h previous beginning-of-line x
;; Next Scr next screen x
;; Prev Scr previous screen x
;; Search find a string x
;; Replace find and replace a string x
;; Newline insert a newline x
;; Paragraph next or previous paragraph x
;; Auto-Fill break lines on spaces x
;; These functions are not part of the base TPU-edt for the following
;; reasons:
;; Free cursor mode is implemented with the emacs picture-mode functions.
;; These functions support moving the cursor all over the screen, however,
;; when the cursor is moved past the end of a line, spaces or tabs are
;; appended to the line - even if no text is entered in that area. In
;; order for a free cursor mode to work exactly like TPU/edt, this trailing
;; whitespace needs to be dealt with in every function that might encounter
;; it. Such global changes are impractical, however, free cursor mode is
;; too valuable to abandon completely, so it has been implemented in those
;; functions where it serves best.
;; The implementation of scroll margins adds overhead to previously
;; simple and often used commands. These commands are now responsible
;; for their normal operation and part of the display function. There
;; is a possibility that this display overhead could adversely affect the
;; performance of TPU-edt on slower computers. In order to support the
;; widest range of computers, scroll margin support is optional.
;; It's actually not known whether the overhead associated with scroll
;; margin support is significant. If you find that it is, please send
;; a note describing the extent of the performance degradation. Be sure
;; to include a description of the platform where you're running TPU-edt.
;; Send your note to the address provided by Gold-V.
;; Even with these differences and limitations, these functions implement
;; important aspects of the real TPU/edt. Those who miss free cursor mode
;; and/or scroll margins will appreciate these implementations.
;;; Code:
;;; Gotta have tpu-edt
(require 'tpu-edt)
;;; Customization variables
(defconst tpu-top-scroll-margin 0
"*Scroll margin at the top of the screen.
Interpreted as a percent of the current window size.")
(defconst tpu-bottom-scroll-margin 0
"*Scroll margin at the bottom of the screen.
Interpreted as a percent of the current window size.")
(defvar tpu-backward-char-like-tpu t
"*If non-nil, in free cursor mode backward-char (left-arrow) works
just like TPU/edt. Otherwise, backward-char will move to the end of
the previous line when starting from a line beginning.")
;;; Global variables
(defvar tpu-cursor-free nil
"If non-nil, let the cursor roam free.")
;;; Hooks -- Set cursor free in picture mode.
;;; Clean up when writing a file from cursor free mode.
(add-hook 'picture-mode-hook 'tpu-set-cursor-free)
(defun tpu-write-file-hook nil
"Eliminate whitespace at ends of lines, if the cursor is free."
(if (and (buffer-modified-p) tpu-cursor-free) (picture-clean)))
(or (memq 'tpu-write-file-hook write-file-hooks)
(setq write-file-hooks
(cons 'tpu-write-file-hook write-file-hooks)))
;;; Utility routines for implementing scroll margins
(defun tpu-top-check (beg lines)
"Enforce scroll margin at the top of screen."
(let ((margin (/ (* (window-height) tpu-top-scroll-margin) 100)))
(cond ((< beg margin) (recenter beg))
((< (- beg lines) margin) (recenter margin)))))
(defun tpu-bottom-check (beg lines)
"Enforce scroll margin at the bottom of screen."
(let* ((height (window-height))
(margin (+ 1 (/ (* height tpu-bottom-scroll-margin) 100)))
;; subtract 1 from height because it includes mode line
(difference (- height margin 1)))
(cond ((> beg difference) (recenter beg))
((> (+ beg lines) difference) (recenter (- margin))))))
;;; Movement by character
(defun tpu-forward-char (num)
"Move right ARG characters (left if ARG is negative)."
(interactive "p")
(if tpu-cursor-free (picture-forward-column num) (forward-char num)))
(defun tpu-backward-char (num)
"Move left ARG characters (right if ARG is negative)."
(interactive "p")
(cond ((not tpu-cursor-free)
(backward-char num))
(tpu-backward-char-like-tpu
(picture-backward-column num))
((bolp)
(backward-char 1)
(picture-end-of-line)
(picture-backward-column (1- num)))
(t
(picture-backward-column num))))
;;; Movement by line
(defun tpu-next-line (num)
"Move to next line.
Prefix argument serves as a repeat count."
(interactive "p")
(let ((beg (tpu-current-line)))
(if tpu-cursor-free (or (eobp) (picture-move-down num))
(next-line-internal num))
(tpu-bottom-check beg num)
(setq this-command 'next-line)))
(defun tpu-previous-line (num)
"Move to previous line.
Prefix argument serves as a repeat count."
(interactive "p")
(let ((beg (tpu-current-line)))
(if tpu-cursor-free (picture-move-up num) (next-line-internal (- num)))
(tpu-top-check beg num)
(setq this-command 'previous-line)))
(defun tpu-next-beginning-of-line (num)
"Move to beginning of line; if at beginning, move to beginnin